<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <button id="btn1">查询</button>
  <button id="btn2">增加</button>
  <button id="btn3">修改</button>
  <button id="btn4">删除</button>

</body>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.js"></script>
<script>
  const btn1 = document.getElementById('btn1');
  const btn2 = document.getElementById('btn2');
  const btn3 = document.getElementById('btn3');
  const btn4 = document.getElementById('btn4');

  // 创建自定义配置的axios对象
  const myAxios = axios.create({
    baseURL: 'http://127.0.0.1:3000'
  });
  // 对某个axios对象进行请求拦截器配置
  myAxios.interceptors.response.use((response) => {
    console.log("响应拦截成功", response);
    if (response.data.code === 10000) {
      return response.data
    } else {
      Promise.reject(response.data.code)
    }
  })

  // 查
  btn1.onclick = function () {
    myAxios({
      url: '/login',
      method: 'GET',
      params: {
        name: 'aaa',
        pass: '123'
      },
    }).then(mes => {
      console.log(mes.data);
    }).catch(err => {
      console.log(err);
    })
  }

</script>

</html>